﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class UIWS07:UIWF
    {
        
        public UIWS07()
        {
         
         }

        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {

            base.QueryCommand(sender, e);
        }


        public override void NewCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!IsNew)
            {
                IsNew = true;
                FARBE = "";
                return;
            }
            if (FARBE == "")
                return;
            dwData = TBMain.NewRow();
            TMV.SetUpNewRow(ref dwData);
            dwData["WAFMANDANT"] = app.Mandant;
            dwData["WAFART"] = ART;
            dwData["WAFVAR"] = VAR;
            dwData["WAFZUART"] = ZUART;
            dwData["WAFZUSATZ"] = FARBE;
            TMV. Insert(dwData);
            vwMaster.View.MoveCurrentToFirst();
            IsNew = false;
            FARBE = "";
            base.NewCommand(sender, e);

        }
        public override void OnZUARTChg()
        {
            base.OnZUARTChg();
        }

        public override void EditCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            base.EditCommand(sender, e);
        }
        public override void DeleteCommand(object sender, System.Windows.RoutedEventArgs e)
        {

            if (dwMaster == null)
                return;
            TMV.DWAF01(dwMaster);
            filter = "WAFART='" + dwMaster["WAFART"].ToString() + "' AND WAFVAR='" + dwMaster["WAFVAR"].ToString() + "' AND WAFZUART='" + dwMaster["WAFZUART"].ToString() + "' AND WAFZUSATZ='" + dwMaster["WAFZUSATZ"].ToString() + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }

        public override void CopyCommand(object sender, System.Windows.RoutedEventArgs e)
        {

            if (!IsCopy)
            {
                IsCopy = true;
                return;
            }
            if (FARBE == "")
                return;
            if (dwMaster == null)
                return;
            dwData = TBMain.NewRow();
            dwData.ItemArray = dwMaster.ItemArray;
            dwData["WAFZUSATZ"] = FARBE;
            TBMain.Rows.InsertAt(dwData, 0);
            vwMaster.View.MoveCurrentToFirst();
            IsCopy = false;
            base.CopyCommand(sender, e);

        }
        public override void SaveCommand(object sender, System.Windows.RoutedEventArgs e)
        {

            try
            {
                if (dwMaster == null)
                    return;
                TMV.UpdateWAFARBEN(dwMaster, app.company, 0);
                base.SaveCommand(sender, e);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (EXAUF.Length < 23)
                return;
            ART = EXAUF.Substring(1, 20);
            VAR = EXAUF.Substring(21, 2);
            dwData = TBMain.NewRow();
            dwData["WAFMANDANT"] = app.Mandant;
            dwData["WAFART"] =ART;
            dwData["WAFVAR"] = VAR;
            dwData["WAFZUART"] = ZUART;
            SResult = TMV.QWAF11(dwData);
            MergeData(SResult, false);
            base.OnEXAUFChg(vlaue);
        }
    }    
}

